import sys

from World import *

# todo: build world
def Factory1():
    w = World(10, 10) 
    w.setContent(5, 5, 1) # wall
    w.setContent(5, 4, 2) # food
    return w

def loadWorld(fileName):
    file = open(fileName, 'r')
    sizeX = int(loadField(file, "sizeX"))
    sizeY = int(loadField(file, "sizeY"))
    w = World(sizeX, sizeY)
    for y in range(sizeY):
        line = file.readline().strip()
        while line == "" or line[0:2] == "//" or line[0] == '#': 
            line = file.readline().strip()
        if len(line) != sizeX:
            print "ERROR: expected line with length " + str(sizeX)
            sys.exit()
        for x in range(sizeX):
            if line[x] == '*' or line[x] == "x" or line[x] == "w":
                w.setContent(x, y, 1)
    file.close() 
    return w
